home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
SNDLIST-
/
CONVERT.C
< prev
next >
Wrap
Text File
|
1988-11-10
|
2KB
|
73 lines
/*
Sound lister
"Convert.c"
*/
#include <sane.h>
#include <ToolboxUtil.h>
static union { /* Largest possible positive double */
unsigned int plusdoubleparts[5];
double plusdouble;
} max = { 0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF };
typedef struct { /* SANE environment flags word */
short unused:1, round:2,
inexact:1, divbyzero:1, overflow:1, underflow:1, invalid:1,
lastround:1, precision:2, halts:5;
} SANEenvword;
extern SANEenvword SANEglobalenv: 0xA4A;
#define FOPSTR2DEC (short)0x0002 /* Pascal string to decimal record */
#define FODEC2STR (short)0x0003 /* Decimal record to Pascal string */
#define FOCSTR2DEC (short)0x0004 /* C string to decimal record */
pascal void DecStr68K() = 0xA9EE; /* _Trap7 */
/* ----- Value of 2 raised to the X power ------------------------------ */
double exp2(x)
double x;
{
elems68k(&x, FOEXP2X);
if (SANEglobalenv.overflow)
return max.plusdouble;
return x;
}
/* ----- Convert Fixed to string and vice versa ------------------------ */
void Fixed2String(x, s)
register Fixed x;
register unsigned char *s;
{
double value;
Decimal dec;
DecForm form;
form.style = FIXEDDECIMAL;
form.digits = 6;
value = Fix2X(x);
fp68k(&form, &value, &dec, FFEXT+FOB2D);
/*Dec2Str(&form, &dec, s);*/
DecStr68K(&form, &dec, s, FODEC2STR);
}
short String2Fixed(s, x)
register unsigned char *s;
register Fixed *x;
{
double value;
Decimal dec;
short index;
short validPrefix;
/*Str2Dec(s, &index, &dec, &validPrefix);*/
DecStr68K(s, &index, &dec, &validPrefix, FOPSTR2DEC);
fp68k(&dec, &value, FFEXT+FOD2B);
*x = X2Fix(&value);
return index;
}